package com.yinhai.util;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.yinhai.activity.LoadingActivity;
import com.yinhai.activity.R;

public class NotificationUtil {
    private Context context;
    public NotificationUtil(Context context)
    {
        this.context=context;
    }
    
    public void showNotification() {
    NotificationManager notificationManager = (
                    NotificationManager)context.getSystemService(
                                    android.content.Context.NOTIFICATION_SERVICE);
    
    Notification notification = new Notification(
                    R.drawable.ic_launcher,context.getString(R.string.app_name), 
                    System.currentTimeMillis());
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
//    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
//    notification.defaults = Notification.DEFAULT_LIGHTS;
//    notification.ledARGB = Color.BLUE;
//    notification.ledOnMS = 5000;
//    notification.defaults=Notification.DEFAULT_SOUND |Notification.DEFAULT_VIBRATE;
    notification.defaults=Notification.DEFAULT_SOUND;
            
    CharSequence contentTitle = context.getString(R.string.app_name); 
    CharSequence contentText = "open "+contentTitle; 
    
    Intent notificationIntent = new Intent(context,LoadingActivity.class);
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
            | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    PendingIntent contentIntent = PendingIntent.getActivity(
                    context, 0, notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(
                    context, contentTitle, contentText, contentIntent);
    notificationManager.notify(0, notification);
    }
    
    public void cancelNotification(){
            NotificationManager notificationManager = (
                            NotificationManager) context.getSystemService(
                                            android.content.Context.NOTIFICATION_SERVICE);
            notificationManager.cancel(0);
    }
}
